package pers.corvey.studyjava.model.form;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import pers.corvey.studyjava.controller.CaptchaController;
import pers.corvey.studyjava.model.User;
import pers.corvey.studyjava.util.ToStringUtils;

public class LoginForm implements MyValidatable {

    @NotNull(message="账号不能为空")
    @Size(min=User.ACCOUNT_MIN_LEN, max=User.ACCOUNT_MAX_LEN, message="账号长度有误")
    private String account;
    
    @NotNull(message="密码不能为空")
    @Size(min=User.PASSWORD_MIN_LEN, max=User.PASSWORD_MAX_LEN, message="密码长度有误")
    private String password;
    
    @NotNull(message="验证码不能为空")
    @Size(min=CaptchaController.CAPTCHA_LENGTH, max=CaptchaController.CAPTCHA_LENGTH, message="验证码长度有误")
    private String captcha;
    
    public LoginForm() {}
    
    public User toUser() {
        User user = new User();
        user.setAccount(getAccount());
        user.setPassword(getPassword());
        return user;
    }
    
    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getCaptcha() {
        return captcha;
    }

    public void setCaptcha(String captcha) {
        this.captcha = captcha;
    }
    
    @Override
    public String toString() {
        return ToStringUtils.objectToString(this);
    }
}
